home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Utilities / Random / Commodore 64c / SOURCE / Instructions.h < prev    next >
Text File  |  1992-07-21  |  4KB  |  145 lines

  1. #define FlagsNZ(z)\
  2.     flags &=~(ZER+NEG); if (z==0) flags|=ZER; else flags |=z&128
  3.  
  4. #define ORA(x) a|=ByteAt(x()); FlagsNZ(a)
  5. #define ASL(x) \
  6.     register word addr;\
  7.     register byte tbyte;\
  8.     addr = x();\
  9.     tbyte = ByteAt(addr);\
  10.     flags &=~(CAR+NEG+ZER);\
  11.     if (tbyte&128) flags |= CAR;\
  12.     if (tbyte=tbyte<<1) flags |=tbyte&128; else flags |=ZER;\
  13.     RAM[addr] = tbyte
  14. #define LSR(x) \
  15.     register word addr;\
  16.     register byte tbyte;\
  17.     addr=x();\
  18.     tbyte=ByteAt(addr);\
  19.     flags &=~(CAR+NEG+ZER);\
  20.     flags |=tbyte&1;\
  21.     if (tbyte=tbyte>>1); else flags |=ZER;\
  22.     RAM[addr]=tbyte
  23. #define BCL(x) \
  24.     register byte tbyte;\
  25.     if (flags&x) pc++; \
  26.     else {\
  27.         tbyte=ImmediateByte();\
  28.         pc++;\
  29.         if (tbyte&128) {\
  30.             pc-=(tbyte^255)+1;\
  31.             return; }\
  32.         pc +=tbyte; }
  33. #define BST(x) \
  34.     register byte tbyte;\
  35.     if (flags&x) {\
  36.         tbyte=ImmediateByte();\
  37.         pc++;\
  38.         if (tbyte&128) {\
  39.             pc-=(tbyte^255)+1;\
  40.             return; }\
  41.         pc +=tbyte; }\
  42.     else pc++;
  43. #define CLR(x) flags &=~x; return
  44. #define SET(x) flags |= x; return
  45. #define AND(x) a &= ByteAt(x()); FlagsNZ(a)
  46. #define BIT(x) \
  47.     register byte tbyte;\
  48.     tbyte=ByteAt(x());\
  49.     flags &=~(ZER+NEG+OVF);\
  50.     if ((a&tbyte)==0) flags |=ZER;\
  51.     flags |=tbyte&(128+64)
  52. #define ROL(x) \
  53.     register word addr;\
  54.     register byte tbyte;\
  55.     addr=x();\
  56.     tbyte=ByteAt(addr);\
  57.     if (flags&CAR) {\
  58.         if (tbyte&128);\
  59.         else flags &=~CAR;\
  60.         tbyte=(tbyte<<1)|1; }\
  61.     else {\
  62.         if (tbyte&128) flags|=CAR;\
  63.         tbyte=tbyte<<1; }\
  64.     FlagsNZ(tbyte);\
  65.     RAM[addr]=tbyte
  66. #define EOR(x)     a^=ByteAt(x());FlagsNZ(a)
  67. #define BCD2DEC(x) ((x&15)+((x&240)>>4)*10)
  68. #define DEC2BCD(x,y) { y=x/10; x -=y*10; y=(y<<4) +x;}
  69. #define ADC(x) \
  70.     register word data;\
  71.     data=ByteAt(x());\
  72.     if (flags&DEC) {\
  73.         data = BCD2DEC(data)+BCD2DEC(a)+((flags&CAR)?1:0);\
  74.         flags &= ~(CAR+OVF+NEG+ZER);\
  75.         if (data>99) {flags|=CAR+OVF;data -=100;}\
  76.         if (data==0) flags|=ZER; else flags |=data&128;\
  77.         DEC2BCD(data,a);}\
  78.     else {\
  79.         data += a+((flags&CAR)?1:0);\
  80.         flags &= ~(CAR+OVF+NEG+ZER);\
  81.         if (data>255) {flags|=OVF+CAR; data &=255;}\
  82.         if (data==0) flags|=ZER; else flags |=data&128;\
  83.         a=data;}
  84. #define ROR(x) \
  85.     register word addr;\
  86.     register byte tbyte;\
  87.     addr=x(); tbyte=ByteAt(addr);\
  88.     if(flags&CAR){if(tbyte&1); else flags&=~CAR;tbyte=(tbyte>>1)|128;}\
  89.     else{if(tbyte&1) flags|=CAR;tbyte=tbyte>>1;}\
  90.     FlagsNZ(tbyte); RAM[addr]=tbyte
  91. #define STA(x) RAM[x()]=a
  92. #define STY(x) RAM[x()]=y
  93. #define STX(y) RAM[y()]=x
  94. #define CPY(x) \
  95.     register byte tbyte;\
  96.     tbyte=ByteAt(x()); flags &=~(CAR+ZER+NEG);\
  97.     if (y==tbyte) flags |=CAR+ZER;\
  98.     else if (y>tbyte) flags |=CAR;\
  99.         else flags |=NEG
  100. #define CPX(y) \
  101.     register byte tbyte;\
  102.     tbyte=ByteAt(y()); flags &=~(CAR+ZER+NEG);\
  103.     if (x==tbyte) flags |=CAR+ZER;\
  104.     else if (x>tbyte) flags |=CAR;\
  105.         else flags |=NEG
  106. #define CMP(x) \
  107.     register byte tbyte;\
  108.     tbyte=ByteAt(x()); flags &=~(CAR+ZER+NEG);\
  109.     if (a==tbyte) flags |=CAR+ZER;\
  110.     else if (a>tbyte) flags |=CAR;\
  111.         else flags |=NEG
  112. #define SBC(x) \
  113.     register int data;\
  114.     data=ByteAt(x());\
  115.     if (flags&DEC) {\
  116.         data = BCD2DEC(a)-BCD2DEC(data)-((flags&CAR)?0:1);\
  117.         flags &= ~(CAR+ZER+NEG+OVF);\
  118.         if (data==0) flags |=ZER+CAR;\
  119.         else if (data>0) flags |=CAR;\
  120.             else {flags|=NEG; data +=100;}\
  121.         DEC2BCD(data,a);}\
  122.     else {\
  123.         data = a-data-((flags&CAR)?0:1);\
  124.         flags &=~(CAR+ZER+OVF+NEG);\
  125.         if (data==0) flags |=ZER+CAR;\
  126.         else if (data>0) flags |=CAR;\
  127.             else flags|=OVF;\
  128.         flags |=data&128;\
  129.         a=data&255;}
  130. #define DECR(x) \
  131.     register word addr; register byte tbyte;\
  132.     addr=x(); tbyte=ByteAt(addr);\
  133.     flags &=~(ZER+NEG);\
  134.     if (--tbyte) flags |=tbyte&128; else flags|=ZER;\
  135.     RAM[addr]=tbyte
  136. #define INCR(x) \
  137.     register word addr; register byte tbyte;\
  138.     addr=x(); tbyte=ByteAt(addr);\
  139.     flags &=~(ZER+NEG);\
  140.     if (++tbyte) flags |=tbyte&128; else flags|=ZER;\
  141.     RAM[addr]=tbyte
  142. #define LDA(x) a=ByteAt(x()); FlagsNZ(a)
  143. #define LDY(x) y=ByteAt(x()); FlagsNZ(y)
  144. #define LDX(y) x=ByteAt(y()); FlagsNZ(x)
  145.